#coding:utf-8
from django import forms
from models import *
from log_dj.models import *
from django.shortcuts import render_to_response
from django.contrib.formtools.wizard import FormWizard
import datetime
from django.contrib.admin import widgets



class ContactWizard(FormWizard):
    def done(self, request, form_list):
        return render_to_response('done.html', {
            'form_data': [form.cleaned_data for form in form_list],
        })

class ContactForm1(forms.Form):
    subject = forms.CharField(max_length=100)
    sender = forms.EmailField()

class ContactForm2(forms.Form):
    message = forms.CharField(widget=forms.Textarea)


class LogSearchForm(forms.Form):
    stardate = forms.DateTimeField(widget=widgets.AdminDateWidget(),label=u'开始日期',required=False)
    startime = forms.TimeField(widget=widgets.AdminTimeWidget(),label=u'开始时间',required=False) 
    enddate = forms.DateTimeField(widget=widgets.AdminDateWidget(),label=u'结束日期',required=False)
    endtime = forms.TimeField(widget=widgets.AdminTimeWidget(),label=u'结束时间',required=False)  
 
    used_sourcename = Distinct.objects.values_list('sourcename', flat=True).distinct() 
    sourcename_choices = [] + [(item, item) for item in used_sourcename] 
    sourcename = forms.MultipleChoiceField(choices=sourcename_choices,widget=forms.CheckboxSelectMultiple,required=False,initial=['Print'])

    used_categorystring = Distinct.objects.values_list('categorystring', flat=True).distinct()
    categorystring_choices = [] + [(item, item) for item in used_categorystring]
    categorystring = forms.MultipleChoiceField(choices=categorystring_choices,widget=forms.CheckboxSelectMultiple,required=False)

    used_type = Distinct.objects.values_list('type', flat=True).distinct()
    type_choices = [] + [(item, item) for item in used_type]
    type = forms.MultipleChoiceField(choices=type_choices,widget=forms.CheckboxSelectMultiple,required=False)

    used_eventcode = Distinct.objects.values_list('eventcode', flat=True).distinct()
    eventcode_choices = [] + [(item, item) for item in used_eventcode]
    eventcode = forms.MultipleChoiceField(choices=eventcode_choices,widget=forms.CheckboxSelectMultiple,required=False)

    used_computername = Distinct.objects.values_list('computername', flat=True).distinct()
    computername_choices = [] + [(item, item) for item in used_computername]
    computername = forms.MultipleChoiceField(label=u"计算机",choices=computername_choices,widget=forms.CheckboxSelectMultiple,required=False)

    used_users = Distinct.objects.values_list('users', flat=True).distinct()
    users_choices = [] + [(item, item) for item in used_users]
    users = forms.MultipleChoiceField(label=u"用户",choices=users_choices,widget=forms.CheckboxSelectMultiple,required=False)


class LogSearchForm1(forms.Form):
    used_sourcename = Distinct.objects.values_list('sourcename', flat=True).distinct()
    sourcename_choices = [] + [(item, item) for item in used_sourcename]
    sourcename = forms.MultipleChoiceField(choices=sourcename_choices,widget=forms.CheckboxSelectMultiple,required=False,initial=
['Print'])

    used_categorystring = Distinct.objects.values_list('categorystring', flat=True).distinct()
    categorystring_choices = [] + [(item, item) for item in used_categorystring]
    categorystring = forms.MultipleChoiceField(choices=categorystring_choices,widget=forms.CheckboxSelectMultiple,required=False)
